import os
from loguru import logger
from application.settings import BASE_DIR, DEBUG

"""
# 日志简单配置
# 具体其他配置 可自行参考 https://github.com/Delgan/loguru
"""

# 移除控制台输出
logger.remove(handler_id=None)

log_path = os.path.join(BASE_DIR, 'logs')
if not os.path.exists(log_path):
    os.mkdir(log_path)

log_path_info = os.path.join(log_path, 'info.log')
log_path_task = os.path.join(log_path, f'task.log')

logger.add(
    log_path_info, rotation="300 MB", retention="3 months", enqueue=True, encoding="UTF-8",
    level="DEBUG" if DEBUG else "INFO",
    filter=lambda record: record['extra'].get('name', 'info') == 'info'
)
logger.add(
    log_path_task, rotation="300 MB", retention="1 months", enqueue=True, encoding="UTF-8",
    level="DEBUG" if DEBUG else "INFO",
    filter=lambda record: record['extra'].get('name', 'info') == 'task'
)

logger_info = logger.bind(name="info")
logger_task = logger.bind(name="task")
# error = logger.add(log_path_error, rotation="00:00", retention="3 days", enqueue=True, encoding="UTF-8", level="ERROR")
